package dao;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import pojo.Account;
import pojo.message.imp.ChatMessage;
import pojo.message.imp.Message;

import java.util.Date;
import java.util.List;

@Component
public interface UserMessageTD {
    @Select("select hav_mes from user_tb where id=#{id}")
    int getMessageCount(@Param("id") String id);
    @Select("select hav_mes from friend_tb where id_m=#{id} and id_f=#{friendId}  ")
    int getMessageCountForFriend(@Param("id") String id,@Param("friendId") String friendId);
    @Select("select id_f from friend_tb where id_m=#{id} ")
    List<String> getFriendsList(@Param("id") String id);//获取朋友列表
    @Select("select id_f from  friend_tb where id_m=#{account.id} and id_f=#{id_f}  ")
    String havFriend(@Param("account") Account account,@Param("id_f") String id_f);
    @Select("select message,date from message_tb where  id_to=#{id_to} and id_from =#{id_from} ")
    List<Message> getMessageForId(@Param("id_from") String id_from, @Param("id_to") String id_to);

    @Insert("insert into message_tb values(#{id_from},#{id_to} ,#{date},#{text} )")
    int insertMessage(@Param("id_from") String id_from, @Param("id_to") String id_to,@Param("date") Date date,@Param("text") String text);
    @Update("update friend_tb set hav_mes=hav_mes+#{count} where id_m=#{id_from} and id_f=#{id_to}")
    int updateMessageCounttoFriend(@Param("id_from") String id_from, @Param("id_to") String id_to,@Param("count") int count);//给朋友的信息更新
    @Update("update user_tb set hav_mes=hav_mes+#{count}  where id=#{id} ")
    int updateMessageCount(@Param("id") String id,@Param("count") int count);
    @Insert("insert into friend_tb values(#{id_m},#{id_f},0)")
    int insertFriend(@Param("id_m") String id_m,@Param("id_f") String id_f);
    @Delete("delete from message_tb where id_to=#{id_to} and id_from=#{id_from} ")
    int deleteMessageForId(@Param("id_from") String id_from, @Param("id_to") String id_to);

}
